﻿using System.Windows;
using System;
using System.Data;
using ReflectionStudio.Core.Events;
using System.Collections;
using System.Collections.Generic;
using WPFExcelReport.Controls;
using WPFExcelReport;
using System.Windows.Controls;
using System.Windows.Media;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for Machine.xaml
    /// </summary>

    public partial class MGANTT
    { 
        public DataTable JOBS
        {
            get
            {
                return Machine.JOBS;
            }
        }
        #region ==BgColor===========
        public static readonly DependencyProperty BgColorProperty = DependencyProperty.Register("BgColor",
            typeof(Color), typeof(MGANTT),
            new FrameworkPropertyMetadata(Color.FromRgb(255,255,255), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBgColorChanged));
        public Color BgColor
        {
            get
            {
                return (Color)GetValue(BgColorProperty);
            }
            set
            {
                SetValue(BgColorProperty, value);
                OnBgColorChg();
            }
        }
        private static void OnBgColorChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as MGANTT;
            if (src != null)
            {
                src.BgColor = (Color)e.NewValue;
            }
        }
        public virtual void OnBgColorChg()
        {
            
        }
        #endregion

        #region ==IsEven===========
        public static readonly DependencyProperty IsEvenProperty = DependencyProperty.Register("IsEven",
        typeof(bool), typeof(MGANTT),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsEvenChanged));
        public bool IsEven
        {
            get
            {
                return (bool)GetValue(IsEvenProperty);
            }
            set
            {
                SetValue(IsEvenProperty, value);
                OnEvenChg(value);
            }
        }
        private static void OnIsEvenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as MGANTT;
            if (src != null)
            {
                src.IsEven = (bool)e.NewValue;
            }
        }
        public virtual void OnEvenChg(bool value)
        {
            if(IsEven)
            {
                BgColor = Color.FromRgb(255, 255, 255);
            }
            else
            {
                BgColor = Color.FromRgb(150, 255, 150);
            }
        }
        #endregion

        public DataRow dwMachine { get; set; }
        public MCALENDAR MCALENDAR { get; set; }
        public UIAM Machine { get; set; }
        public string MachineID
        {
            get
            {
                return Machine.MachineID;
            }
        }
        public string Description { get; set; }

        public double TotalBlocks
        {
            get
            {
                return MCALENDAR.TotalBlocks;
            }
        }

        public double PIXELS
        {
            get
            {
                return MCALENDAR.PIXELS;
            }
        }

        public Grid MainGrid
        {
            get { return (Grid)this.FindName("MGrid"); }
        }
        public MGANTT()
        {
            InitializeComponent();
         } 
        public void SetUp(bool _IsEven)
        { 
            IsEven = _IsEven;
            this.Name = MachineID;
            
            LineNow.SetValue(Grid.ColumnProperty, MCALENDAR.CurrentBlock);
            int counts = Convert.ToInt16(TotalBlocks);
            //Splilter.SetValue(Grid.ColumnSpanProperty, counts);
            ColumnDefinition cd;
            for (int i = 0; i < TotalBlocks; i++)
            {
                cd = new ColumnDefinition();
                cd.Width = new GridLength(PIXELS);
                MGrid.ColumnDefinitions.Add(cd);
            }
            Height = Machine.Height;
        }
        public void ReSetGrid()
        {
            foreach (ColumnDefinition cd in MGrid.ColumnDefinitions)
            {
                cd.Width = new GridLength(PIXELS);
            }
        }
    }
}
